package com.tan.steamship.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author tanlongjie
 * @Desc
 * @date 2024/11/25
 * @since 1.0
 */
@Data
public class CommonResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private boolean success;
    private String code;
    private String message;
    private T data;

    // 默认构造方法
    public CommonResponse() {
    }

    // 带参数的构造方法
    public CommonResponse(boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 静态方法，用于快速创建成功和失败的响应
    public static <T> CommonResponse<T> success(T data) {
        return new CommonResponse<>(true, "200", "成功", data);
    }

    public static <T> CommonResponse<T> success() {
        return new CommonResponse<>(true, "200", "成功", null);
    }

    public static <T> CommonResponse<T> failure(String message) {
        return new CommonResponse<>(false, "500", message, null);
    }

}
